/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.NVBH;

import DAO.KhachHangDao;
import POJO.KhachHang;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kim
 */
public class frQuanLyKhachHang extends javax.swing.JInternalFrame {

	/**
	 * Creates new form GuiDanhMucKhachHang
	 */
	private int TSD;// tong so dong trong bang hoa don
	private int THT; //trang hiện tại
	private int SD;// hien thi bao nhieu dong tron trang

	public frQuanLyKhachHang() {
		initComponents();
		TSD = soDongDuLieu();
		SD = 20;
		THT = 0;
		load(SD, THT);
		setTxt();
	}

	public String KiemTraDuLieuMa() {
		String str = "";
		if (jtfMaKH.getText().equals("")) {
			str += "- Xin chọn khác hàng trên bảng ! \r\n";
		}
		return str;
	}

	private boolean kiemTraSoDT() {
		boolean kq = false;
		try {
			int tmp = Integer.parseInt(jtfSoDienThoai.getText().trim());
			kq = true;
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(this, "Số điện thoại chỉ nhập số:", "Thông báo lỗi", JOptionPane.ERROR_MESSAGE);
			jtfSoDienThoai.requestFocus();
			jtfSoDienThoai.selectAll();
			return kq;
		} finally {
			return kq;
		}
	}

	public String KiemTraDuLieu() {
		String str = "";
		if (jtfTenKH.getText().equals("")) {
			str += "- Chưa nhập tên khách hàng ! \r\n";
		}
		if (jtfDiaChi.getText().equals("")) {
			str += "- Chưa nhập địa chỉ ! \r\n";
		}
		if (jtfSoDienThoai.getText().equals("")) {
			str += "- Chưa nhập số điện thoại ! \r\n";
		}
		return str;
	}

	private int soDongDuLieu() {
		int tmp = 0;
		KhachHangDao dao = new KhachHangDao();
		try {
			tmp = dao.laySoDong();
		} catch (Exception e) {
		}
		return tmp;
	}

	public void load(int soDong, int trangHienTai) {
		TSD = soDongDuLieu();

		ArrayList<KhachHang> dsKhachHang = null;
		try {
			dsKhachHang = KhachHangDao.layDanhSachPhanTrang(soDong, trangHienTai);

		} catch (Exception e) {
		}
		String[] columns = new String[]{"STT", "Mã khách hàng", "Tên khách hàng", "Địa chỉ", "Điện thoại"};
		DefaultTableModel model = new DefaultTableModel(null, columns);
		int i = 1;
		for (KhachHang kh : dsKhachHang) {
			Object[] items = new Object[]{
				i,
				kh.getMaKH(),
				kh.getTenKH(),
				kh.getDiaChi(),
				kh.getDienThoai()
			};
			i++;
			//int maLSP = sp.getMaLSP();
			model.addRow(items);
		}
		jtDSKhachHang.setModel(model);
		int[] va = {10, 10, 30, 30, 30};
		int[] pt = new int[5];
		for (int l = 0; l < 5; l++) {
			pt[l] = jtDSKhachHang.getWidth() * va[l] / 100;
			jtDSKhachHang.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
		if (jtDSKhachHang.getRowCount() > 0) {
			loadKhachHangLenTexbox(0);
		}
	}

	public void loadKhachHangLenTexbox(int dong) {

		Object ma = jtDSKhachHang.getValueAt(dong, 1);
		Object ten = jtDSKhachHang.getValueAt(dong, 2);
		Object dia = jtDSKhachHang.getValueAt(dong, 3);
		Object dt = jtDSKhachHang.getValueAt(dong, 4);

		jtfMaKH.setText(ma.toString());
		jtfTenKH.setText(ten.toString());
		jtfDiaChi.setText(dia.toString());
		jtfSoDienThoai.setText(dt.toString());

	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel4 = new javax.swing.JPanel();
              jLabel5 = new javax.swing.JLabel();
              jPanel1 = new javax.swing.JPanel();
              jtfMaKH = new javax.swing.JTextField();
              jtfTenKH = new javax.swing.JTextField();
              jLabel1 = new javax.swing.JLabel();
              jLabel2 = new javax.swing.JLabel();
              jLabel3 = new javax.swing.JLabel();
              jtfDiaChi = new javax.swing.JTextField();
              jLabel4 = new javax.swing.JLabel();
              jtfSoDienThoai = new javax.swing.JTextField();
              jPanel2 = new javax.swing.JPanel();
              jbtnMoi = new javax.swing.JButton();
              jbtnThem = new javax.swing.JButton();
              jbtnXoa = new javax.swing.JButton();
              jbtnSua = new javax.swing.JButton();
              jbtnHienThi = new javax.swing.JButton();
              jPanel3 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              jtDSKhachHang = new javax.swing.JTable();
              jPanel6 = new javax.swing.JPanel();
              jButton3 = new javax.swing.JButton();
              jButton1 = new javax.swing.JButton();
              jButton5 = new javax.swing.JButton();
              jButton4 = new javax.swing.JButton();
              lbPhanTrang = new javax.swing.JLabel();

              setClosable(true);
              setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
              setIconifiable(true);
              setMaximizable(true);
              setResizable(true);

              jLabel5.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel5.setText("QUẢN LÝ KHÁCH HÀNG");

              javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
              jPanel4.setLayout(jPanel4Layout);
              jPanel4Layout.setHorizontalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel5)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel4Layout.setVerticalGroup(
                     jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel4Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel5)
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jtfMaKH.setEnabled(false);

              jtfTenKH.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtfTenKHActionPerformed(evt);
                     }
              });
              jtfTenKH.addInputMethodListener(new java.awt.event.InputMethodListener() {
                     public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                     }
                     public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                            jtfTenKHInputMethodTextChanged(evt);
                     }
              });
              jtfTenKH.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtfTenKHKeyReleased(evt);
                     }
              });
              jtfTenKH.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
                     public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                            jtfTenKHVetoableChange(evt);
                     }
              });

              jLabel1.setText("Mã khách hàng:");

              jLabel2.setText("Tên khách hàng:");

              jLabel3.setText("Địa chỉ:");

              jtfDiaChi.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtfDiaChiActionPerformed(evt);
                     }
              });
              jtfDiaChi.addInputMethodListener(new java.awt.event.InputMethodListener() {
                     public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                     }
                     public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                            jtfDiaChiInputMethodTextChanged(evt);
                     }
              });
              jtfDiaChi.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtfDiaChiKeyReleased(evt);
                     }
              });
              jtfDiaChi.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
                     public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                            jtfDiaChiVetoableChange(evt);
                     }
              });

              jLabel4.setText("Số điện thoại:");

              jtfSoDienThoai.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jtfSoDienThoaiActionPerformed(evt);
                     }
              });
              jtfSoDienThoai.addInputMethodListener(new java.awt.event.InputMethodListener() {
                     public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                     }
                     public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                            jtfSoDienThoaiInputMethodTextChanged(evt);
                     }
              });
              jtfSoDienThoai.addKeyListener(new java.awt.event.KeyAdapter() {
                     public void keyReleased(java.awt.event.KeyEvent evt) {
                            jtfSoDienThoaiKeyReleased(evt);
                     }
              });
              jtfSoDienThoai.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
                     public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                            jtfSoDienThoaiVetoableChange(evt);
                     }
              });

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGap(118, 118, 118)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(30, 30, 30)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jtfMaKH, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jtfTenKH, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                                   .addComponent(jtfDiaChi, javax.swing.GroupLayout.Alignment.TRAILING)
                                   .addComponent(jtfSoDienThoai, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(50, 50, 50))
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfMaKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel1))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfTenKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel3))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jtfSoDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                   .addComponent(jLabel4))
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jbtnMoi.setText("Mới");
              jbtnMoi.addMouseListener(new java.awt.event.MouseAdapter() {
                     public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jbtnMoiMouseClicked(evt);
                     }
              });
              jbtnMoi.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnMoiActionPerformed(evt);
                     }
              });

              jbtnThem.setText("Thêm");
              jbtnThem.setEnabled(false);
              jbtnThem.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnThemActionPerformed(evt);
                     }
              });

              jbtnXoa.setText("Xóa");
              jbtnXoa.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnXoaActionPerformed(evt);
                     }
              });

              jbtnSua.setText("Sửa");
              jbtnSua.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnSuaActionPerformed(evt);
                     }
              });

              jbtnHienThi.setText("Hiển thị");
              jbtnHienThi.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnHienThiActionPerformed(evt);
                     }
              });

              javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
              jPanel2.setLayout(jPanel2Layout);
              jPanel2Layout.setHorizontalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap(168, Short.MAX_VALUE)
                            .addComponent(jbtnMoi)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jbtnThem)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnXoa)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnSua)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnHienThi)
                            .addContainerGap(179, Short.MAX_VALUE))
              );
              jPanel2Layout.setVerticalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jbtnMoi)
                                   .addComponent(jbtnThem)
                                   .addComponent(jbtnXoa)
                                   .addComponent(jbtnSua)
                                   .addComponent(jbtnHienThi))
                            .addGap(0, 0, Short.MAX_VALUE))
              );

              jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách khách hàng"));

              jtDSKhachHang.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Mã KH", "Tên khách hàng", "Địa chỉ", "Điện thoại"
                     }
              ));
              jtDSKhachHang.addMouseListener(new java.awt.event.MouseAdapter() {
                     public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jtDSKhachHangMouseClicked(evt);
                     }
              });
              jScrollPane1.setViewportView(jtDSKhachHang);

              jButton3.setText("|<");
              jButton3.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton3ActionPerformed(evt);
                     }
              });

              jButton1.setText("<");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                     }
              });

              jButton5.setText(">|");
              jButton5.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton5ActionPerformed(evt);
                     }
              });

              jButton4.setText(">");
              jButton4.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jButton4ActionPerformed(evt);
                     }
              });

              lbPhanTrang.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbPhanTrang.setText("0");

              javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
              jPanel6.setLayout(jPanel6Layout);
              jPanel6Layout.setHorizontalGroup(
                     jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel6Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbPhanTrang)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton5)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel6Layout.setVerticalGroup(
                     jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jButton3)
                                   .addComponent(jButton1)
                                   .addComponent(jButton5)
                                   .addComponent(jButton4)
                                   .addComponent(lbPhanTrang)))
              );

              javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
              jPanel3.setLayout(jPanel3Layout);
              jPanel3Layout.setHorizontalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
                     .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              );
              jPanel3Layout.setVerticalGroup(
                     jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
              );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(0, 0, 0))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(0, 0, 0))
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

       private void jtfTenKHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfTenKHActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfTenKHActionPerformed

       private void jtfTenKHInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtfTenKHInputMethodTextChanged
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfTenKHInputMethodTextChanged

       private void jtfTenKHKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfTenKHKeyReleased
		// TODO add your handling code here:
		//       vbtSua();
       }//GEN-LAST:event_jtfTenKHKeyReleased

       private void jtfTenKHVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtfTenKHVetoableChange
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfTenKHVetoableChange

       private void jtfDiaChiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfDiaChiActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiActionPerformed

       private void jtfDiaChiInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtfDiaChiInputMethodTextChanged
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiInputMethodTextChanged

       private void jtfDiaChiKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDiaChiKeyReleased
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiKeyReleased

       private void jtfDiaChiVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtfDiaChiVetoableChange
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfDiaChiVetoableChange

       private void jtfSoDienThoaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSoDienThoaiActionPerformed
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiActionPerformed

       private void jtfSoDienThoaiInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jtfSoDienThoaiInputMethodTextChanged
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiInputMethodTextChanged

       private void jtfSoDienThoaiKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfSoDienThoaiKeyReleased
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiKeyReleased

       private void jtfSoDienThoaiVetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtfSoDienThoaiVetoableChange
		// TODO add your handling code here:
       }//GEN-LAST:event_jtfSoDienThoaiVetoableChange

       private void jbtnMoiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnMoiMouseClicked
		// TODO add your handling code here:
       }//GEN-LAST:event_jbtnMoiMouseClicked

    private void jbtnMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnMoiActionPerformed
	    // TODO add your handling code here:        
//	    jtfTenKH.setEditable(true);
//	    jtfTenKH.setFocusable(true);
//	    jtfDiaChi.setEditable(true);
//	    jtfSoDienThoai.setEnabled(true);
	    if (jbtnMoi.getText().equals("Mới")) {
		    khachMoi();

	    } else {
		    huyKhongThem(0);
	    }

    }//GEN-LAST:event_jbtnMoiActionPerformed
	private void khachMoi() {
		jtfMaKH.setText("");
		jtfTenKH.setText("");
		jtfDiaChi.setText("");
		jtfSoDienThoai.setText("");
		jbtnThem.setEnabled(true);
		jbtnMoi.setText("Hủy");
		jbtnXoa.setEnabled(false);
		jbtnSua.setEnabled(false);
	}

	private void huyKhongThem(int dong) {
		jbtnXoa.setEnabled(true);
		jbtnSua.setEnabled(true);
		jbtnThem.setEnabled(false);
		jbtnMoi.setText("Mới");
		loadKhachHangLenTexbox(dong);
	}
    private void jbtnHienThiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnHienThiActionPerformed
	    // TODO add your handling code here:
	    load(SD, THT);
	    huyKhongThem(0);
    }//GEN-LAST:event_jbtnHienThiActionPerformed

    private void jbtnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemActionPerformed
	    // TODO add your handling code here:
	    String kt = KiemTraDuLieu();
	    if (kt == "") {
		    String TenKH = this.jtfTenKH.getText();
		    String DiaChi = this.jtfDiaChi.getText();
		    if (!kiemTraSoDT()) {
			    return;
		    }
		    String DienThoai = this.jtfSoDienThoai.getText();

		    KhachHang kh = new KhachHang();

		    kh.setTenKH(TenKH);
		    kh.setDiaChi(DiaChi);
		    kh.setDienThoai(DienThoai);

		    boolean kq = KhachHangDao.them(kh);
		    if (kq == true) {
			    JOptionPane.showMessageDialog(this, "Thêm khách hàng thành công", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
			    huyKhongThem(0);
			    load(SD, THT);
		    } else {
			    JOptionPane.showMessageDialog(this, "Thêm khách hàng thất bại", "Cảnh báo!!!", JOptionPane.WARNING_MESSAGE);
		    }
	    } else {
		    JOptionPane.showMessageDialog(this, kt.toString(), "Cảnh báo!!!", JOptionPane.INFORMATION_MESSAGE);
	    }
    }//GEN-LAST:event_jbtnThemActionPerformed

    private void jbtnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXoaActionPerformed
	    // TODO add your handling code here:
	    String kt = KiemTraDuLieuMa();
	    if (kt == "") {
		    int maKH = Integer.parseInt(jtfMaKH.getText());

		    boolean kq = KhachHangDao.xoa(maKH);
		    if (kq == true) {
			    JOptionPane.showMessageDialog(this, "Xoá khách hàng thành công ", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
			    load(SD, THT);
		    } else {
			    JOptionPane.showMessageDialog(this, "Xoá khách hàng thất bại", "Cảnh báo!!!", JOptionPane.WARNING_MESSAGE);
		    }
	    } else {
		    JOptionPane.showMessageDialog(this, kt.toString(), "Cảnh báo!!!", JOptionPane.INFORMATION_MESSAGE);
	    }
    }//GEN-LAST:event_jbtnXoaActionPerformed

    private void jbtnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSuaActionPerformed
	    // TODO add your handling code here:
	    String kt = KiemTraDuLieu();
	    if (kt == "") {
		    int maKH = Integer.parseInt(this.jtfMaKH.getText());
		    String TenKH = this.jtfTenKH.getText();
		    String DiaChi = this.jtfDiaChi.getText();
		    String DienThoai = this.jtfSoDienThoai.getText();
		    if (!kiemTraSoDT()) {
			    return;
		    }
		    KhachHang kh = new KhachHang();

		    kh.setMaKH(maKH);
		    kh.setTenKH(TenKH);
		    kh.setDiaChi(DiaChi);
		    kh.setDienThoai(DienThoai);

		    boolean kq = KhachHangDao.capNhat(kh);
		    if (kq == true) {
			    JOptionPane.showMessageDialog(this, "Cập nhật khách hàng thành công", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
			    load(SD, THT);
		    } else {
			    JOptionPane.showMessageDialog(this, "Cập nhật khách hàng thất bại", "Cảnh báo!!!", JOptionPane.WARNING_MESSAGE);
		    }
	    } else {
		    JOptionPane.showMessageDialog(this, kt.toString(), "Cảnh báo!!!", JOptionPane.INFORMATION_MESSAGE);
	    }
    }//GEN-LAST:event_jbtnSuaActionPerformed

    private void jtDSKhachHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtDSKhachHangMouseClicked
	    // TODO add your handling code here:
	    int dong = this.jtDSKhachHang.getSelectedRow();
	    if (dong != -1) {
		    huyKhongThem(dong);
	    }

    }//GEN-LAST:event_jtDSKhachHangMouseClicked

       private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
		// TODO add your handling code here:
		// ve dau tien
		THT = 0;
		load(SD, THT);
		setTxt();

       }//GEN-LAST:event_jButton3ActionPerformed

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		// TODO add your handling code here:
		//ve trang truoc
		if (THT != 0) {
			THT -= 1;
			load(SD, THT);
		}
		setTxt();

       }//GEN-LAST:event_jButton1ActionPerformed

       private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
		// TODO add your handling code here:
		// ve cuoi

		THT = TSD / SD;
		load(SD, THT);

		setTxt();

       }//GEN-LAST:event_jButton5ActionPerformed

       private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
		// TODO add your handling code here:
		if (THT < TSD / SD) {
			THT += 1;
			load(SD, THT);
		}
		setTxt();

       }//GEN-LAST:event_jButton4ActionPerformed
	private void setTxt() {
		lbPhanTrang.setText(Integer.toString(THT + 1) + "/" + Integer.toString(TSD / SD + 1));
	}
       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JButton jButton1;
       private javax.swing.JButton jButton3;
       private javax.swing.JButton jButton4;
       private javax.swing.JButton jButton5;
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel3;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabel5;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel2;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanel4;
       private javax.swing.JPanel jPanel6;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JButton jbtnHienThi;
       private javax.swing.JButton jbtnMoi;
       private javax.swing.JButton jbtnSua;
       private javax.swing.JButton jbtnThem;
       private javax.swing.JButton jbtnXoa;
       private javax.swing.JTable jtDSKhachHang;
       private javax.swing.JTextField jtfDiaChi;
       private javax.swing.JTextField jtfMaKH;
       private javax.swing.JTextField jtfSoDienThoai;
       private javax.swing.JTextField jtfTenKH;
       private javax.swing.JLabel lbPhanTrang;
       // End of variables declaration//GEN-END:variables
}
